home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / ads / a-numran < prev    next >
Text File  |  1996-02-12  |  5KB  |  99 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                  A D A . N U M E R I C S . R A N D O M                   --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.3 $                              --
  10. --                                                                          --
  11. --        Copyright (C) 1992,1993,1994 Free Software Foundation, Inc.       --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. --  This package provides the basic support used for the Float_Random and
  37. --  Discrete_Random children of Ada.Numerics. In this package, the generator
  38. --  state is exposed for access but this is a private package so no problem.
  39.  
  40. private package Ada.Numerics.Random is
  41.  
  42.    --  All the arithmetic is done using a base type that is at least
  43.    --  32 bits long (one's complement or two's complement, does not
  44.    --  matter). It also must be at least as large as integer.
  45.  
  46.    type Int_Range is range
  47.       Long_Integer'Min (Long_Integer (Integer'First), (-2 ** 31) + 1) ..
  48.       Long_Integer'Max (Long_Integer (Integer'Last),  (+2 ** 31) - 1);
  49.  
  50.    type Int is new Int_Range'Base;
  51.    subtype Nat is Int range 0 .. Int'Last;
  52.    --  The types that we will actually use
  53.  
  54.    --  The following declarations define the type State, which is used as the
  55.    --  underlying type for both Generator and State in the user level packages
  56.  
  57.    Larger_Lag  : constant := 25;
  58.    Smaller_Lag : constant := 11;
  59.    --  Lag values used for modular accessing of the state vector
  60.  
  61.    type Lag_Range is mod Larger_Lag;
  62.    --  Range of larger lag is length of state vector
  63.  
  64.    type State_Vector is array (Lag_Range) of Float;
  65.  
  66.    type State is record
  67.       Lagged_Outputs : State_Vector;
  68.       Borrow         : Float;
  69.       R, S           : Lag_Range;
  70.    end record;
  71.  
  72.    subtype Uniformly_Distributed is Float range 0.0 .. 1.0;
  73.    --  Range of random numbers
  74.  
  75.    procedure Random (S : in out State; U : out Uniformly_Distributed);
  76.    --  Obtain next random number, updating State
  77.  
  78.    function Make_State (Starter : Int := 3E+7) return State;
  79.    --  Build a state from the given integer value. The default value for
  80.    --  Int is used to build the default starting generator configurations.
  81.  
  82.    procedure Reset (S : out State; Initiator : in Integer);
  83.    --  Set state from given integer value
  84.  
  85.    procedure Reset (S : out State);
  86.    --  Set state from current time
  87.  
  88.    Max_Image_Width : constant := (24 + 1) * 25 + 24;
  89.    --  The 24 + 1 is for one floating point value plus a comma, and there
  90.    --  are up to Larger_Lag number of these, followed by one additional value
  91.  
  92.    function Image (S : State)  return String;
  93.    --  Convert state to canonical string format (see body for format)
  94.  
  95.    function Value (S : String) return State;
  96.    --  Convert string returned by previous image call back to State
  97.  
  98. end Ada.Numerics.Random;
  99.